package com.shopnight.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shopnight.entity.AddressOption;
import com.shopnight.service.AddressOptionService;
import com.shopnight.mapper.AddressOptionMapper;
import java.util.List;
import com.shopnight.vo.AddressOptionVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;

/**
* @author 13201
* @description 针对表【address_option】的数据库操作Service实现
* @createDate 2022-09-13 16:06:13
*/
@Service
public class AddressOptionServiceImpl extends ServiceImpl<AddressOptionMapper, AddressOption>
    implements AddressOptionService{

    @Autowired
    AddressOptionMapper addressOptionMapper;


    @Override
    public AddressOptionVo getAddressAll(Integer orgId) {

        List<AddressOption> AddressOptionOne = baseMapper.selectList(
                new LambdaQueryWrapper<AddressOption>()
                        .eq(AddressOption::getOrgId ,orgId)
                        .eq(AddressOption::getOptionLevel,1)
                );
        List<AddressOptionVo.OptionLevelOne> ListOne = AddressOptionOne.stream().map(item -> {
            AddressOptionVo.OptionLevelOne optionLevelOne = new AddressOptionVo.OptionLevelOne();
            BeanUtils.copyProperties(item, optionLevelOne);
            return optionLevelOne;
        }).collect(Collectors.toList());


        List<AddressOption> AddressOptionTow = baseMapper.selectList(
                new LambdaQueryWrapper<AddressOption>()
                        .eq(AddressOption::getOptionLevel,2)
        );
        List<AddressOptionVo.OptionLevelTwo> ListTwo = AddressOptionTow.stream().map(item -> {
            AddressOptionVo.OptionLevelTwo optionLevelTwo = new AddressOptionVo.OptionLevelTwo();
            BeanUtils.copyProperties(item, optionLevelTwo);
            return optionLevelTwo;
        }).collect(Collectors.toList());


        AddressOptionVo addressOptionVo = new AddressOptionVo();
        addressOptionVo.setOptionLevelOneList(ListOne);
        addressOptionVo.setOptionLevelTwoList(ListTwo);

        return addressOptionVo;
    }

}




